﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RuleCode.Enum;
using RuleCode.Table;

namespace map.manage
{
    public partial class broker : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bind1();
                bind2();
                bind3();
                GridViewBind();
            }
        }
        /// <summary>
        /// 县
        /// </summary>
        private void bind1()
        {
            string sheng = zfunction.Province;
            RuleCode.Table.县 x = RuleCode.Table.县.Find(" 省编码 = '" + sheng + "' ");
            DropDownList1.Items.Clear();
            foreach (DataRow item in x.MyTable.Rows)
            {
                DropDownList1.Items.Add(item["县编码"].ToString());
            }
           
            //DropDownList1.DataBind();
        }
        /// <summary>
        /// 区
        /// </summary>
        private void bind2()
        {
            string xian = DropDownList1.Text;
            RuleCode.Table.区 x = RuleCode.Table.区.Find(" 县编码 = '" + xian + "' ");
            DropDownList2.Items.Clear();
            foreach (DataRow item in x.MyTable.Rows)
            {
                DropDownList2.Items.Add(item["区编码"].ToString());

            }
           
        }

        /// <summary>
        /// 区域表格
        /// </summary>
        private void bind3()
        {
            //RuleCode.Table.区域 x = RuleCode.Table.区域.Find(" 区编码 = '" + DropDownList2.Text + "' "
            //    + " and 县编码 = '" + DropDownList1.Text + "' ");
            //DropDownList3.DataSource = x.MyTable.DefaultView;
            //DropDownList3.DataTextField = "区域编码";
            //DropDownList3.DataValueField = "区域编码";
            //DropDownList3.DataBind();
          

        }


        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            bind2();
            bind3();
        }

        protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
        {
            bind3();
            GridViewBind();
        }
        protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
        {
            GridViewBind();
        }
        //todo:是否删，先不做删除
        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string id = GridView1.DataKeys[e.RowIndex].Value.ToString();
            BizArea uc = BizArea.Find(" recid = '" + id + "'", "RECID");
            uc.Delete();
            GridViewBind();
        }

        protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
            //审核通过
            string id = GridView1.DataKeys[e.NewEditIndex].Value.ToString();
            cbuser uc = cbuser.Find(" recid = '" + id + "'", "RECID");
            if (uc.BokerStatus == BrokerStatus.Common)
            {
                return;
            }
            else
            {
                if (uc.BokerStatus == BrokerStatus.Require)
                {
                    uc.BokerStatus = BrokerStatus.Approved;
                    uc.Modify();
                }

            }
            
            GridViewBind();



        }
        private void GridViewBind()
        {
          
            RuleCode.Table.cbuser x = RuleCode.Table.cbuser.Find(" 区编码 = '" + DropDownList2.Text + "' "
                                                                 + " and 县编码 = '" + DropDownList1.Text + "' " +" and BokerStatus!=0");
            this.GridView1.DataSource = x.MyTable;

            this.GridView1.DataBind();
        }
    }
}
